package com.oops.appquery;
import java.io.BufferedReader;

import java.io.InputStreamReader;
import org.json.JSONArray;
import org.json.JSONObject;

public class Shopping {
	
	public Shopping(String shop)throws Exception{
		
	
		framework obj=new framework();
		BufferedReader BR = new BufferedReader(new InputStreamReader(obj.gsearch("https://www.googleapis.com/shopping/search/v1/public/products?country=US&q=" 
		+ shop.replace(" ", "%20") + "&key=AIzaSyCkqEoJU4KDyyF4WxPoT3NVyIUti7RnrAw")));
		StringBuilder SB = new StringBuilder();
		String line1 = null;
		while ((line1 = BR.readLine()) != null)
		{
		SB.append(line1 + "\n");
		}
		BR.close();
		String line=SB.toString();
		JSONObject json = new JSONObject(line);
		JSONArray gson=json.getJSONArray("items");
		for(int i=0;i<json.length();i++)
		{
		JSONObject kson=gson.getJSONObject(i);
		JSONObject lson=kson.getJSONObject("product");
		String s=lson.getString("title");
		String k=lson.getString("link");
		System.out.println(s);
		System.out.println(k);
		System.out.println();
		}
	    
    }
}


